home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / edit / thesrc20.zip / scroll.c < prev    next >
C/C++ Source or Header  |  1995-01-26  |  12KB  |  298 lines

  1. /***********************************************************************/
  2. /* SCROLL.C - SCROLL commands                                          */
  3. /* This file contains all commands that can be assigned to function    */
  4. /* keys or typed on the command line.                                  */
  5. /***********************************************************************/
  6. /*
  7.  * THE - The Hessling Editor. A text editor similar to VM/CMS xedit.
  8.  * Copyright (C) 1991-1995 Mark Hessling
  9.  *
  10.  * This program is free software; you can redistribute it and/or
  11.  * modify it under the terms of the GNU General Public License as
  12.  * published by the Free Software Foundation; either version 2 of
  13.  * the License, or any later version.
  14.  *
  15.  * This program is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18.  * General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with this program; if not, write to:
  22.  *
  23.  *    The Free Software Foundation, Inc.
  24.  *    675 Mass Ave,
  25.  *    Cambridge, MA 02139 USA.
  26.  *
  27.  *
  28.  * If you make modifications to this software that you feel increases
  29.  * it usefulness for the rest of the community, please email the
  30.  * changes, enhancements, bug fixes as well as any and all ideas to me.
  31.  * This software is going to be maintained and enhanced as deemed
  32.  * necessary by the community.
  33.  *
  34.  * Mark Hessling                     email: M.Hessling@gu.edu.au
  35.  * 36 David Road                     Phone: +61 7 849 7731
  36.  * Holland Park                      Fax:   +61 7 875 5314
  37.  * QLD 4121
  38.  * Australia
  39.  */
  40.  
  41. /*
  42. $Id: scroll.c 2.0 1995/01/26 16:31:59 MH Release MH $
  43. */
  44.  
  45. #include <stdio.h>
  46.  
  47. #include "the.h"
  48. #include "proto.h"
  49.  
  50. /***********************************************************************/
  51. #ifdef PROTO
  52. short scroll_page(short direction,LINETYPE num_pages,bool scrollbar)
  53. #else
  54. short scroll_page(direction,num_pages,scrollbar)
  55. short direction;
  56. LINETYPE num_pages;
  57. bool scrollbar;
  58. #endif
  59. /***********************************************************************/
  60. {
  61. /*-------------------------- external data ----------------------------*/
  62.  extern bool scroll_cursor_stay;
  63.  extern bool curses_started;
  64. /*--------------------------- local data ------------------------------*/
  65.  short rc=RC_OK;
  66.  short y=0,x=0,save_y=0;
  67.  bool save_scroll_cursor_stay=scroll_cursor_stay;
  68. /*--------------------------- processing ------------------------------*/
  69. #ifdef TRACE
  70.  trace_function("scroll.c:  scroll_page");
  71. #endif
  72. /*---------------------------------------------------------------------*/
  73. /* If scrolling backward and already on TOF, return.                   */
  74. /* If scrolling forward and already on EOF, return.                    */
  75. /*---------------------------------------------------------------------*/
  76.  if ((direction == DIRECTION_BACKWARD
  77.       && CURRENT_TOF)
  78.  ||  (direction == DIRECTION_FORWARD
  79.       && CURRENT_BOF))
  80.    {
  81. #ifdef TRACE
  82.     trace_return();
  83. #endif
  84.     return(RC_TOF_EOF_REACHED);
  85.    }
  86. /*---------------------------------------------------------------------*/
  87. /* If scrolling via the scroll bars, ALWAYS leave the cursor on the    */
  88. /* screen line.                                                        */
  89. /*---------------------------------------------------------------------*/
  90.  if (scrollbar)
  91.     save_scroll_cursor_stay = TRUE;
  92. /*---------------------------------------------------------------------*/
  93. /* Get current focus row if cursor is to stay on current focus line... */
  94. /*---------------------------------------------------------------------*/
  95.  if (save_scroll_cursor_stay)
  96.     save_y = get_row_for_focus_line(CURRENT_VIEW->focus_line,CURRENT_VIEW->current_row);
  97. /*---------------------------------------------------------------------*/
  98. /* Find the new current line, num_pages away...                        */
  99. /*---------------------------------------------------------------------*/
  100.  post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  101.  CURRENT_VIEW->current_line = find_next_current_line(num_pages,direction);
  102.  build_current_screen();
  103.  if (save_scroll_cursor_stay)
  104.    {
  105.     save_y = get_row_for_tof_eof(save_y,current_screen);
  106.     CURRENT_VIEW->focus_line = CURRENT_SCREEN.sl[save_y].line_number;
  107.     pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  108.     build_current_screen();
  109.    }
  110.  else
  111.    {
  112.     CURRENT_VIEW->focus_line = calculate_focus_line(CURRENT_VIEW->focus_line,
  113.                                                     CURRENT_VIEW->current_line);
  114.     pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  115.    }
  116. /*---------------------------------------------------------------------*/
  117. /* If curses has started, display screen and sort out cursor position..*/
  118. /*---------------------------------------------------------------------*/
  119.  if (curses_started)
  120.    {
  121.     getyx(CURRENT_WINDOW,y,x);
  122.     display_current_screen();
  123.     if (CURRENT_VIEW->current_window != WINDOW_COMMAND)
  124.       {
  125.        y = get_row_for_focus_line(CURRENT_VIEW->focus_line,
  126.                                CURRENT_VIEW->current_row);
  127.        wmove(CURRENT_WINDOW,y,x);
  128.        if (scrollbar)
  129.           wrefresh(CURRENT_WINDOW);
  130.       }
  131.    }
  132. #ifdef TRACE
  133.  trace_return();
  134. #endif
  135.  if (CURRENT_TOF || CURRENT_BOF)
  136.     return(RC_TOF_EOF_REACHED);
  137.  else
  138.     return(RC_OK);
  139. }
  140. /***********************************************************************/
  141. #ifdef PROTO
  142. short scroll_line(short direction,LINETYPE num_lines,bool scrollbar,bool escreen)
  143. #else
  144. short scroll_line(direction,num_lines,scrollbar,escreen)
  145. short direction;
  146. LINETYPE num_lines;
  147. bool scrollbar;
  148. bool escreen;
  149. #endif
  150. /***********************************************************************/
  151. {
  152. /*-------------------------- external data ----------------------------*/
  153.  extern bool scroll_cursor_stay;
  154.  extern bool curses_started;
  155. /*--------------------------- local data ------------------------------*/
  156.  short rc=RC_OK;
  157.  unsigned short x=0,y=0;
  158.  bool on_file_edge=FALSE,on_screen_edge=FALSE;
  159.  short number_focus_rows=0;
  160.  bool leave_cursor=FALSE;
  161.  LINETYPE new_focus_line=0L,new_current_line=0L,edge_line=0L;
  162.  LINETYPE longy=0L,longx=0L;
  163.  ROWTYPE yoff1=0,yoff2=0;
  164. /*--------------------------- processing ------------------------------*/
  165. #ifdef TRACE
  166.  trace_function("scroll.c:  scroll_line");
  167. #endif
  168. /*---------------------------------------------------------------------*/
  169. /* If this function is called via scrollbar...                         */
  170. /* If scrolling backward and already on TOF, return.                   */
  171. /* If scrolling forward and already on EOF, return.                    */
  172. /*---------------------------------------------------------------------*/
  173.  if (scrollbar)
  174.    {
  175.     if ((direction == DIRECTION_BACKWARD
  176.          && CURRENT_TOF)
  177.     ||  (direction == DIRECTION_FORWARD
  178.          && CURRENT_BOF))
  179.       {
  180. #ifdef TRACE
  181.        trace_return();
  182. #endif
  183.        return(RC_TOF_EOF_REACHED);
  184.       }
  185.    }
  186.  calculate_scroll_values(&number_focus_rows,&new_focus_line,
  187.                          &new_current_line,
  188.                          &on_screen_edge,&on_file_edge,
  189.                          &leave_cursor,direction);
  190.  switch(scrollbar)
  191.    {
  192.     case FALSE:
  193.          getyx(CURRENT_WINDOW,y,x);
  194.          if (direction == DIRECTION_FORWARD)
  195.            {
  196.             edge_line = CURRENT_FILE->number_lines+1L;
  197.             yoff1 = y - ((leave_cursor) ? 0 : 1);
  198.             yoff2 = y + number_focus_rows;
  199.            }
  200.          else
  201.            {
  202.             edge_line = 0L;
  203.             yoff1 = y + ((leave_cursor) ? 0 : 1);
  204.             yoff2 = y - number_focus_rows;
  205.            }
  206. /*---------------------------------------------------------------------*/
  207. /* If the cursor is on the edgs of the window or on the edge of the    */
  208. /* file and tabbing to the command line is set, tab to the command line*/
  209. /* provided the command line is ON.                                    */
  210. /*---------------------------------------------------------------------*/
  211.          if (!escreen
  212.          && (on_screen_edge || on_file_edge))
  213.            {
  214.             if (CURRENT_WINDOW_COMMAND == NULL)
  215.               {
  216.                getyx(CURRENT_WINDOW,y,x);
  217.                if (direction == DIRECTION_FORWARD)
  218.                   rc = find_first_focus_line(&y);
  219.                else
  220.                   rc = find_last_focus_line(&y);
  221.                if (rc == RC_OK)
  222.                  {
  223.                   CURRENT_VIEW->focus_line = CURRENT_SCREEN.sl[y].line_number;
  224.                   pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  225.                   wmove(CURRENT_WINDOW,y,x);
  226.                  }
  227.                break;
  228.               }
  229.             cursor_cmdline(1);
  230.             break;
  231.            }
  232. /*---------------------------------------------------------------------*/
  233. /* If the cursor is on the edge of the file...                         */
  234. /*---------------------------------------------------------------------*/
  235.          if (on_file_edge)
  236.            {
  237. /*---------------------------------------------------------------------*/
  238. /* ... and the current row is the edge of the file, stay there.        */
  239. /*---------------------------------------------------------------------*/
  240.             if (CURRENT_VIEW->current_line == edge_line)
  241.                break;
  242. /*---------------------------------------------------------------------*/
  243. /* ... and the edge of the file is above or below the current row,     */
  244. /* scroll the window.                                                  */
  245. /*---------------------------------------------------------------------*/
  246.             CURRENT_VIEW->current_line = new_current_line;
  247.             build_current_screen();
  248.             display_current_screen();
  249.             y = get_row_for_focus_line(CURRENT_VIEW->focus_line,CURRENT_VIEW->current_row);
  250.             wmove(CURRENT_WINDOW,y,x);
  251.             break;
  252.            }
  253. /*---------------------------------------------------------------------*/
  254. /* If on the edge of the window, scroll the window.                    */
  255. /*---------------------------------------------------------------------*/
  256.          if (on_screen_edge)
  257.            {
  258.             CURRENT_VIEW->current_line = new_current_line;
  259.             post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  260.             CURRENT_VIEW->focus_line = new_focus_line;
  261.             pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  262.                                 build_current_screen();
  263.             display_current_screen();
  264.             wmove(CURRENT_WINDOW,yoff1,x);
  265.             break;
  266.            }
  267. /*---------------------------------------------------------------------*/
  268. /* We are in the middle of the window, so just move the cursor up or   */
  269. /* down 1 line.                                                        */
  270. /*---------------------------------------------------------------------*/
  271.          wmove(CURRENT_WINDOW,yoff2,x);
  272.          post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  273.          CURRENT_VIEW->focus_line = new_focus_line;
  274.          pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  275.          break;
  276.     case TRUE:
  277.          if (CURRENT_VIEW->current_window != WINDOW_COMMAND)
  278.             get_cursor_position(&longy,&longx,&new_focus_line,&new_current_line);
  279.          rc = advance_current_line((direction == DIRECTION_FORWARD) ? num_lines : -num_lines);
  280.          if (CURRENT_VIEW->current_window != WINDOW_COMMAND)
  281.            {
  282.             cursor_move(TRUE,(short)longy,(short)longx);
  283.             show_heading();
  284.             if (CURRENT_VIEW->id_line)
  285.                wnoutrefresh(CURRENT_WINDOW_IDLINE);
  286.             wrefresh(CURRENT_WINDOW);
  287.            }
  288.          break;
  289.         }
  290. #ifdef TRACE
  291.  trace_return();
  292. #endif
  293.  if (CURRENT_TOF || CURRENT_BOF)
  294.     return(RC_TOF_EOF_REACHED);
  295.  else
  296.     return(RC_OK);
  297. }
  298.